package com.inspur.xiaoju.security;

import org.springframework.stereotype.Component;

import java.security.SecureRandom;

@Component
public class SurveyUtilPlugin implements SecurityPlugin {
    
    private static final String SURVEY_PATH_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int SURVEY_PATH_LENGTH = 8;
    private final SecureRandom random = new SecureRandom();
    
    @Override
    public String genSurveyPath() {
        StringBuilder sb = new StringBuilder(SURVEY_PATH_LENGTH);
        for (int i = 0; i < SURVEY_PATH_LENGTH; i++) {
            int randomIndex = random.nextInt(SURVEY_PATH_ALPHABET.length());
            sb.append(SURVEY_PATH_ALPHABET.charAt(randomIndex));
        }
        return sb.toString();
    }
}